package cn.iocoder.yudao.module.train.service.classsetting;

import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.module.train.dal.dataobject.connectDTO.ClassSettingDTO;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.train.controller.admin.classsetting.vo.*;
import cn.iocoder.yudao.module.train.dal.dataobject.classsetting.ClassSettingDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.train.dal.mysql.classsetting.ClassSettingMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.train.enums.ErrorCodeConstants.*;

/**
 * 排课 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class ClassSettingServiceImpl implements ClassSettingService {

    @Resource
    private ClassSettingMapper classSettingMapper;

    @Override
    public Long createClassSetting(ClassSettingSaveReqVO createReqVO) {
        // 插入
        ClassSettingDO classSetting = BeanUtils.toBean(createReqVO, ClassSettingDO.class);
        classSettingMapper.insert(classSetting);

        // 返回
        return classSetting.getId();
    }

    @Override
    public void updateClassSetting(ClassSettingSaveReqVO updateReqVO) {
        // 校验存在
        validateClassSettingExists(updateReqVO.getId());
        // 更新
        ClassSettingDO updateObj = BeanUtils.toBean(updateReqVO, ClassSettingDO.class);
        classSettingMapper.updateById(updateObj);
    }

    @Override
    public void deleteClassSetting(Long id) {
        // 校验存在
        validateClassSettingExists(id);
        // 删除
        classSettingMapper.deleteById(id);
    }

    @Override
        public void deleteClassSettingListByIds(List<Long> ids) {
        // 删除
        classSettingMapper.deleteByIds(ids);
        }


    private void validateClassSettingExists(Long id) {
        if (classSettingMapper.selectById(id) == null) {
            throw exception(CLASS_SETTING_NOT_EXISTS);
        }
    }

    @Override
    public ClassSettingDO getClassSetting(Long id) {
        return classSettingMapper.selectById(id);
    }

    @Override
    public List<ClassSettingDO> getClassSettingList(ClassSettingPageReqVO pageReqVO) {
        return classSettingMapper.selectList(pageReqVO);
    }

    @Override
    public List<ClassSettingDTO> getClassSettingListDetail(ClassSettingPageReqVO pageReqVO) {
        return classSettingMapper.selectListDetail(pageReqVO);
    }
}
